@extends('backend.layouts.app')

@section('title', $title = $gameList->id ? '游戏编辑' : '添加游戏' )

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">网站管理</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">

        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{ $title }}</legend>
        </fieldset>

        <form class="layui-form layui-form-pane" method="POST"
              action="{{ $gameList->id ? route('game_list.update', $gameList->id) : route('game_list.store') }}">
            {{ csrf_field() }}
            <input type="hidden" name="_method" class="mini-hidden" value="{{ $gameList->id ? 'PATCH' : 'POST' }}">

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">平台</label>
                    <div class="layui-input-block">
                        <select name="main_game_plat_code" lay-verify="required" lay-search="">
                            <option value="">请选择平台</option>
                            @foreach($plats as $plat)
                                <option value={{$plat->main_game_plat_code}} @if($gameList->main_game_plat_code===$plat->main_game_plat_code) selected @endif>{{$plat->main_game_plat_name}}</option>
                            @endforeach
                        </select>
                    </div>

                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">中文名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="cn_name" lay-verify="" placeholder="请输入中文名"
                               autocomplete="off" class="layui-input" value="{{ old('cn_name',$gameList->cn_name) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">请填写1到64位字符串</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">英文名</label>
                    <div class="layui-input-inline">
                        <input type="text" name="en_name" lay-verify="" placeholder="请输入英文名"
                               autocomplete="off" class="layui-input" value="{{ old('en_name',$gameList->en_name) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">请填写1到64位字符串</div>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="编号">编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pc_game_code" lay-verify="" placeholder="请输入编号"
                               autocomplete="off" class="layui-input"
                               value="{{ old('pc_game_code',$gameList->pc_game_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="编号扩展">编号扩展</label>
                    <div class="layui-input-inline">
                        <input type="text" name="pc_game_deputy_code" lay-verify=""
                               placeholder="请输入编号扩展"
                               autocomplete="off" class="layui-input"
                               value="{{ old('pc_game_deputy_code',$gameList->pc_game_deputy_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="移动端编号">移动端编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="mobile_game_code" lay-verify=""
                               placeholder="请输入移动端编号"
                               autocomplete="off" class="layui-input"
                               value="{{ old('mobile_game_code',$gameList->mobile_game_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="移动端编号扩展">移动端编号扩展</label>
                    <div class="layui-input-inline">
                        <input type="text" name="mobile_game_deputy_code" lay-verify=""
                               placeholder="请输入移动端编号扩展"
                               autocomplete="off" class="layui-input"
                               value="{{ old('mobile_game_deputy_code',$gameList->mobile_game_deputy_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="匹配编号">匹配编号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="record_match_code" lay-verify=""
                               placeholder="请输入匹配编号"
                               autocomplete="off" class="layui-input"
                               value="{{ old('record_match_code',$gameList->record_match_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="匹配编号扩展">匹配编号扩展</label>
                    <div class="layui-input-inline">
                        <input type="text" name="record_match_deputy_code" lay-verify=""
                               placeholder="请输入匹配编号扩展"
                               autocomplete="off" class="layui-input"
                               value="{{ old('record_match_deputy_code',$gameList->record_match_deputy_code) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">1到32位，字母、数字、破折号（ - ）以及下划线（ _ ）</div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">游戏分类</label>
                    <div class="layui-input-block">
                        <select name="category" lay-verify="required" lay-search="">
                            <option value="">请选择游戏分类</option>
                            @foreach($gameCategories as $gameCategory)
                                <option value={{$gameCategory->code}} @if($gameList->category===$gameCategory->code) selected @endif>{{$gameCategory->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">游戏类型</label>
                    <div class="layui-input-block">
                        <select name="type" lay-verify="required" lay-search="">
                            <option value="">请选择游戏类型</option>
                            @foreach($gameTypes as $gameType)
                                <option value={{$gameType->code}} @if($gameList->type===$gameType->code) selected @endif>{{$gameType->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">游戏线数</label>
                    <div class="layui-input-block">
                        <select name="line_num" lay-verify="" lay-search="">
                            <option value="">请选择游戏线数</option>
                            @foreach($gameLines as $gameLine)
                                <option value={{$gameLine->code}} @if($gameList->type===$gameLine->code) selected @endif>{{$gameLine->name}}</option>
                            @endforeach
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label" title="返奖率">返奖率</label>
                    <div class="layui-input-inline">
                        <input type="text" name="money_return_rate" lay-verify="rate"
                               placeholder="请输入返奖率"
                               autocomplete="off" class="layui-input"
                               value="{{ old('money_return_rate',$gameList->money_return_rate) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">不超过1的小数，最多保留4位小数</div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label" title="奖金池">奖金池</label>
                    <div class="layui-input-inline">
                        <input type="text" name="bonus_pool" lay-verify=""
                               placeholder="请输入奖金池"
                               autocomplete="off" class="layui-input"
                               value="{{ old('bonus_pool',$gameList->bonus_pool) }}">
                    </div>
                    <div class="layui-form-mid layui-word-aux">必须为数字</div>
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">试玩</label>
                    <div class="layui-input-block">
                        <input type="radio" name="able_demo" value="1" title="是"
                               @if($gameList->able_demo) checked @endif>
                        <input type="radio" name="able_demo" value="0" title="否"
                               @if(!$gameList->able_demo) checked @endif>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">推荐</label>
                    <div class="layui-input-block">
                        <input type="radio" name="able_recommend" value="1" title="是"
                               @if($gameList->able_recommend) checked @endif>
                        <input type="radio" name="able_recommend" value="0" title="否"
                               @if(!$gameList->able_recommend) checked @endif>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">大厅</label>
                    <div class="layui-input-block">
                        <input type="radio" name="is_lobby" value="1" title="是"
                               @if($gameList->is_lobby) checked @endif>
                        <input type="radio" name="is_lobby" value="0" title="否"
                               @if(!$gameList->is_lobby) checked @endif>
                    </div>
                </div>

            </div>
            @if(isset($gameList))
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-inline">
                            <select name="status" lay-verify="required" lay-search="">
                                <option value="">直接选择或搜索选择</option>
                                <option value=0 @if((int)($gameList->status)===0) selected @endif>关闭</option>
                                <option value=1
                                        @if((int)($gameList->status)===1 || !isset($gameList->id)) selected @endif>启用
                                </option>
                                <option value=2 @if((int)($gameList->status)===2) selected @endif>维护</option>
                            </select>
                        </div>
                    </div>
                </div>
            @endif
            <div class="layui-form-item">
                <div class="layui-upload">
                    <button type="button" class="layui-btn url" id="img1">图片1</button>
                    <input type="hidden" name="img1" id="img1_url" lay-verify=""
                           value=""/>
                    <div class="layui-upload-list">
                        @if(!empty($gameList->getImg1Url()))
                            <img class="layui-upload-img" src="{{$gameList->getImg1Url()}}" id="img1_file_path"
                                 style="max-width: 520px;" _height="280">
                        @else
                            <img class="layui-upload-img" src="" id="img1_file_path"
                                 style="max-width: 520px;" _height="280">
                        @endif
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-upload">
                    <button type="button" class="layui-btn url" id="img2">图片2</button>
                    <input type="hidden" name="img2" id="img2_url"
                           value=""/>
                    <div class="layui-upload-list">
                        @if(!empty($gameList->getImg2Url()))
                            <img class="layui-upload-img" src="{{$gameList->getImg2Url()}}" id="img2_file_path"
                                 style="max-width: 520px;" _height="280">
                        @else
                            <img class="layui-upload-img" src="" id="img2_file_path"
                                 style="max-width: 520px;" _height="280">
                        @endif
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </form>
    </div>
@endsection

@section('scripts')
    <script>
        layui.use('form', function () {
            var form = layui.form;

            form.on('checkbox(plats_id)', function (data) {
                if (data.elem.checked) {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = false;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', 'rate');
                } else {
                    document.getElementById(data.elem.getAttribute('data-id')).disabled = true;
                    document.getElementById(data.elem.getAttribute('data-id')).setAttribute('lay-verify', '');
                }

            });

            form.verify({
                rate: [
                    /^0\.\d{1,4}/
                    , '比率必须大于等于0保留一到四位小数，并且小于1，'
                ]
            });
        });

    </script>

    <script>
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadUrlImg1 = upload.render({
                elem: '#img1' // 绑定元素
                , url: '{{ route('upload.image') }}?folder=gameList&shearParam=200*200&object_id={{$group ?? 0}}' // 上传接口
                , field: 'upload_file'
                , done: function (res) {
                    if (res.success == true) {
                        $("#img1_url").val(res.file_uri);
                        $("#img1_file_path").attr("src", res.file_path);
                    }
                    //上传完毕回调
                    console.log(res);
                }
                , error: function () {
                    //请求异常回调
                    layer.alert('上传失败，请重试!', 2);
                }
            });

            var uploadUrlImg2 = upload.render({
                elem: '#img2' // 绑定元素
                , url: '{{ route('upload.image') }}?folder=gameList&shearParam=200*120&object_id={{$group ?? 0}}' // 上传接口
                , field: 'upload_file'
                , done: function (res) {
                    if (res.success == true) {
                        $("#img2_url").val(res.file_uri);
                        $("#img2_file_path").attr("src", res.file_path);
                    }
                    //上传完毕回调
                    console.log(res);
                }
                , error: function () {
                    //请求异常回调
                    layer.alert('上传失败，请重试!', 2);
                }
            });


        });
    </script>
@endsection